 /*
 * @description: 秒杀专区(暂时不开发)
 * @Author: along
 * @Date: 2021-06-15
 * @Last Modified by: along
 * @Last Modified time: 2021-06-15
 */
<template>
    <div
        class="falseSaleActive"
        @click="emitEvent(102)"
        v-if="isLoad"
    >
        <div
            class="__wrap"
            :style="{
                background: 'linear-gradient(135deg, #FF7F00 0%, #F93226 100%)',
                borderRadius: '8px'
            }"
        >
            <div class="__header">
                <div class="__left">
                    <img
                        src="https://cdn.zsdx.cn/student-app/images/active-home/sale_logo.png"
                        class="__logo"
                    >
                    <div
                        v-if="showDate"
                        class="__date"
                    >
                        <div
                            v-if="!!(~~timeDate.day)"
                            class="__day"
                        >
                            {{ timeDate.day }}
                        </div>
                        <div
                            v-if="!!(~~timeDate.day)"
                            class="__day_text"
                        >
                            天
                        </div>
                        <div class="__day">
                            {{ timeDate.hour }}
                        </div>
                        <div class="__side">
                            :
                        </div>
                        <div class="__day">
                            {{ timeDate.minutes }}
                        </div>
                        <div class="__side">
                            :
                        </div>
                        <div class="__day">
                            {{ timeDate.seconds }}
                        </div>
                    </div>
                </div>
                <div class="__right">
                    <div
                        v-for="(row,index) in formData.time_list.slice(0,2)"
                        :key="index"
                        class="__time"
                        :style="{marginRight: index === 0 ? '24px' : '0px'}"
                    >
                        <div class="__time_date">
                            {{ row.start_time | filterTime }}
                        </div>
                        <div class="__time_status">
                            {{ row.start_time | filterStatus(row.end_time) }}
                        </div>
                    </div>
                    <div class="__back_wrap">
                        <img
                            src="https://cdn.zsdx.cn/student-app/images/active-home/flash_back.png"
                            class="__back"
                        >
                    </div>
                </div>
            </div>
            <div
                :style="{
                    width: formData.time_list[curentIndex]['datalist'].length < 3 ? '335px' : '345px'
                }"
            >
                <template v-if="formData.time_list[curentIndex]['datalist'].length < 3">
                    <div
                        v-for="(row,index) in formData.time_list[curentIndex]['datalist']"
                        :key="index"
                        class="__list"
                    >
                        <img
                            :src="row.goods_cover"
                            class="__cover"
                        >
                        <div class="__info">
                            <p class="__title">
                                {{ row.goods_title }}
                            </p>
                            <div
                                v-if="!!row.goods_discount_vip"
                                class="__card"
                            >
                                <div class="__discount">
                                    {{ row.goods_discount_vip }}折
                                </div>
                                <div class="__card_wrap">
                                    <img
                                        src="https://cdn.zsdx.cn/student-app/images/active-home/flase_card.png"
                                        class="__card_logo"
                                    >
                                </div>
                            </div>
                            <div class="__button">
                                <p class="__icon">¥</p>
                                <p class="__price">{{ row.goods_price }}</p>
                                <p class="__price_origin">¥{{ row.goods_price_origin }}</p>
                                <p class="__price_text">马上抢</p>
                                <img
                                    src="https://cdn.zsdx.cn/student-app/images/active-home/flash_button.png"
                                    class="__button_bg"
                                >
                            </div>
                        </div>
                    </div>
                </template>
                <template v-else>
                    <div class="__shop">
                        <div
                            v-for="(row,index) in formData.time_list[curentIndex]['datalist']"
                            :key="index"
                            class="__items"
                        >
                            <img
                                :src="row.goods_cover"
                                class="__cover"
                            >
                            <p class="__title">
                                {{ row.goods_title }}
                            </p>
                            <div class="__info">
                                <p class="__icon">¥</p>
                                <p class="__price">{{ row.goods_price }}</p>
                                <div
                                    v-if="!!row.goods_discount_vip"
                                    class="__card"
                                >
                                    <div class="__discount">
                                        {{ row.goods_discount_vip }}折
                                    </div>
                                    <div class="__card_wrap">
                                        <img
                                            src="https://cdn.zsdx.cn/student-app/images/active-home/flase_card_small.png"
                                            class="__card_logo"
                                        >
                                    </div>
                                </div>
                            </div>
                            <div class="__button">
                                马上抢
                            </div>
                        </div>
                    </div>
                </template>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'FlashSaleActive',
    props: {
        // baseconfig: {
        //     type: Object,
        //     default: () => {}
        // },
        index: {//存在多个相同组件,查询当前位置
            type: Number,
            default: () => {}
        }
    },
    data () {
        return {
            // rate: '0px 0px 0px 0px',
            isLoad: false,
            formData: {
                "time_list": [
                    {
                        "time_no": "tm_ba71fcc887796",
                        "start_time": 1623726720,
                        "end_time": 1623759000
                    },
                    {
                        "time_no": "tm_a3eadd70781dd",
                        "start_time": 1623738720,
                        "end_time": 1623749520
                    },
                    {
                        "time_no": "tm_6f41f7ea34744",
                        "start_time": 1623742320,
                        "end_time": 1623771120
                    }
                ],
                "time_goods_map": {
                    "tm_ba71fcc887796": [
                        {
                            "sale_no": "sl_45f0ab6fe1ff9",
                            "goods_no": "go_a44f83f61c1b7",
                            "goods_title": "viki临期商品7viki临期商品7viki临期商品7viki临期商品7viki临期商品7viki临期商品7viki临期商品7viki临期商品7",
                            "goods_cover": "http://pic.wxhand.com/dev/wei_image/8e23bc3adbca6f50e980082ef19b71c5.png",
                            "goods_price": 1,
                            "goods_price_pay": 1,
                            "goods_price_origin": "495.89",
                            "discount_price": 494.89,
                            "goods_num": 11,
                            "sale_num": 0,
                            "status": 2,
                            "student_rebate_money": 0,
                            "stuagent_rebate_money": 9.82,
                            "has_vip_discount": 0,
                            "goods_discount_vip": 9.9,
                            "goods_price_vip": "1.00"
                        },{
                            "sale_no": "sl_45f0ab6fe1ff9",
                            "goods_no": "go_a44f83f61c1b7",
                            "goods_title": "viki临期商品7viki临期商品7viki临期商品7viki临期商品7viki临期商品7viki临期商品7viki临期商品7viki临期商品7",
                            "goods_cover": "http://pic.wxhand.com/dev/wei_image/8e23bc3adbca6f50e980082ef19b71c5.png",
                            "goods_price": 1,
                            "goods_price_pay": 1,
                            "goods_price_origin": "495.89",
                            "discount_price": 494.89,
                            "goods_num": 11,
                            "sale_num": 0,
                            "status": 2,
                            "student_rebate_money": 0,
                            "stuagent_rebate_money": 9.82,
                            "has_vip_discount": 0,
                            "goods_discount_vip": 9.9,
                            "goods_price_vip": "1.00"
                        },{
                            "sale_no": "sl_45f0ab6fe1ff9",
                            "goods_no": "go_a44f83f61c1b7",
                            "goods_title": "viki临期商品7viki临期商品7viki临期商品7viki临期商品7viki临期商品7viki临期商品7viki临期商品7viki临期商品7",
                            "goods_cover": "http://pic.wxhand.com/dev/wei_image/8e23bc3adbca6f50e980082ef19b71c5.png",
                            "goods_price": 1,
                            "goods_price_pay": 1,
                            "goods_price_origin": "495.89",
                            "discount_price": 494.89,
                            "goods_num": 11,
                            "sale_num": 0,
                            "status": 2,
                            "student_rebate_money": 0,
                            "stuagent_rebate_money": 9.82,
                            "has_vip_discount": 0,
                            "goods_discount_vip": 9.9,
                            "goods_price_vip": "1.00"
                        }
                    ],
                    "tm_a3eadd70781dd": [
                        {
                            "sale_no": "sl_2716486d048c5",
                            "goods_no": "go_90390f07a8ae0",
                            "goods_title": "viki测试食品",
                            "goods_cover": "http://pic.wxhand.com/dev/wei_image/c8b7ba40dd253d42d69981b48025103a.png",
                            "goods_price": 1,
                            "goods_price_pay": 1,
                            "goods_price_origin": "3.00",
                            "discount_price": 2,
                            "goods_num": 33,
                            "sale_num": 0,
                            "status": 1,
                            "student_rebate_money": 0,
                            "stuagent_rebate_money": 0,
                            "has_vip_discount": 0,
                            "goods_discount_vip": 0,
                            "goods_price_vip": "1.00"
                        },
                        {
                            "sale_no": "sl_fcb0383737edd",
                            "goods_no": "go_012ec3536f5ec",
                            "goods_title": "12312",
                            "goods_cover": "http://pic.wxhand.com/dev/wei_image/5597dceebba8a966873d7213f7d7ec25.jpeg",
                            "goods_price": 11,
                            "goods_price_pay": 11,
                            "goods_price_origin": "10000.00",
                            "discount_price": 9989,
                            "goods_num": 1,
                            "sale_num": 0,
                            "status": 1,
                            "student_rebate_money": 0,
                            "stuagent_rebate_money": 0.42,
                            "has_vip_discount": 0,
                            "goods_discount_vip": 0,
                            "goods_price_vip": "11.00"
                        }
                    ],
                    "tm_6f41f7ea34744": [
                        {
                            "sale_no": "sl_fcb0383737edd",
                            "goods_no": "go_012ec3536f5ec",
                            "goods_title": "12312",
                            "goods_cover": "http://pic.wxhand.com/dev/wei_image/5597dceebba8a966873d7213f7d7ec25.jpeg",
                            "goods_price": 11,
                            "goods_price_pay": 11,
                            "goods_price_origin": "10000.00",
                            "discount_price": 9989,
                            "goods_num": 1,
                            "sale_num": 0,
                            "status": 1,
                            "student_rebate_money": 0,
                            "stuagent_rebate_money": 0.42,
                            "has_vip_discount": 0,
                            "goods_discount_vip": 0,
                            "goods_price_vip": "11.00"
                        }
                    ]
                }
            },
            curentIndex: 0,
            timeDate: {
                day: '',
                hour: '',
                minutes: '',
                seconds: ''
            },
            count_timeout: null,
            showDate: false
        };
    },
    filters: {
        filterTime (val) {
            const hours = new Date(val * 1000).getHours();
            const minutes = new Date(val * 1000).getMinutes();
            const repet = val => {
                return Number(val) < 10 ? '0' + val : val;
            };

            return repet(hours) + ':' + repet(minutes);
        },
        filterStatus(startTime, endTime) {
            const currTime = Date.parse(new Date())/1000;
            const todayTime = Date.parse(new Date())/1000+24*60*60;

            if(currTime > endTime){
                return '已结束';
            } else if(currTime < startTime && startTime <= todayTime){
                return '即将开始';
            } else if(currTime < startTime && startTime >= todayTime){
                return '明日预告';
            } else{
                return '抢购中';
            }
        }
    },
    computed: {
        time_no () {
            return this.formData.time_list[this.curentIndex]['time_no'];
        }
    },
    watch: {
        curentIndex (val) {
            this.countDown(this.formData.time_list[val]['start_time'] * 1000, this.formData.time_list[val]['end_time'] * 1000);
        }
        //圆角单位转换
        // baseconfig:  {
        //     handler: function (val, oldVal) {
        //         let rateValue = val.style.borderRadius;

        //         this.rate = rateValue.replace(/rpx/g, 'px');
        //         this.isLoad = true;
        //     },
        //     deep: true
        // }
    },
    mounted () {

        // if(JSON.stringify(this.baseconfig.style) !== '{}') {//回填圆角
        //     let rateValue = this.baseconfig.style.borderRadius;

        //     this.rate = rateValue.replace(/rpx/g, 'px');
        // }

        setTimeout(() => {
            this.initData();
        }, 100);

        // this.countDown();
    },
    methods: {
        initData () {
            for(let key=0; key<this.formData.time_list.length; key++) {
                const time_no = this.formData.time_list[key]['time_no'];

                this.formData.time_list[key]['datalist'] = this.formData.time_goods_map[time_no];
            }

            this.countDown(this.formData.time_list[0]['start_time'] * 1000, this.formData.time_list[0]['end_time'] * 1000);

            this.isLoad = true;
        },

        /**
         * @description 轮播图切换
         */
        handleChange (event) {
            this.curentIndex = event;
            console.log('event', event);
        },

        /**
         * @description 点击组件，向上级传递点击类型
         */
        emitEvent (type) {
            this.$emit('emit', {
                type: type,//组件类型
                index: this.index//组件位置
            });
        },

        /**
         * @deprecated 处理倒计时
         * @param {Number}  start_time  //开始时间
         * @param {Number}  end_time    //结束时间
         * @param {Number}  type        //类型 0:已结束 1:进行中 2:未开始
         *  desc: 只要不是已结束 一直递归下去更新时间
         */
        countDown (start_time, end_time) {
            const now_date = new Date().getTime();
            const now_type = Number(end_time) < Number(now_date) ? 0 : (Number(start_time) > Number(now_date) ? 2 : 1);

            if(now_type === 0) {
                this.showDate = false;
                clearTimeout(this.count_timeout);
                return false;
            }

            this.showDate = true;

            const wait_time = now_type == 1 ? (end_time - now_date) : (start_time - now_date);
            const days = parseInt(wait_time / (1000 * 60 * 60 * 24));
            const hours = parseInt((wait_time % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
            const minutes = parseInt((wait_time % (1000 * 60 * 60)) / (1000 * 60));
            const seconds = ((wait_time % (1000 * 60)) / 1000).toFixed(0);
            const repair = data => {
                if(data < 10) return '0' + data;
                return data;
            };

            this.timeDate = {
                day: repair(days),
                hour: repair(hours),
                minutes: repair(minutes),
                seconds: repair(seconds)
            };
            this.count_timeout = setTimeout(() => {
                this.countDown(start_time, end_time);
            }, 1000);
        },
    }
};
</script>

<style lang="less" scoped>
.falseSaleActive {
    width: 375px;
    box-sizing: border-box;
    border: 1px #ffffff solid;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(242, 242, 242, 1);
    .__wrap {
        box-sizing: border-box;
        padding: 0 0 20px 0;
        width: 355px;
        display: flex;
        flex-direction: column;
        align-items: center;
        .__header {
            width: 355px;
            height: 53px;
            display: flex;
            align-items: center;
            box-sizing: border-box;
            justify-content: space-between;
            background: rgba(255, 255, 255, 0.2);
            .__left {
                display: flex;
                align-items: center;
                .__logo {
                    width: 74px;
                    height: 17px;
                    margin: 0 10px;
                }
                .__date {
                    height: 18px;
                    display: flex;
                    align-items: center;
                    .__day {
                        width: 18px;
                        height: 18px;
                        background: rgba(255, 255, 255, 1);
                        border-radius: 2px;
                        text-align: center;
                        line-height: 18px;
                        color: rgba(255, 41, 37, 1);
                        font-size: 12px;
                        font-weight: 500;
                    }
                    .__day_text {
                        color: rgba(255, 41, 37, 1);
                        font-size: 10px;
                        margin: 0 3px;
                    }
                    .__side {
                        color: rgba(255, 255, 255, 1);
                        font-size: 14px;
                        font-weight: 500;
                        margin: 0 3px;
                    }
                }
            }
            .__right {
                display: flex;
                align-items: center;
                .__back_wrap {
                    width: 24px;
                    height: 53px;
                    background: rgba(255, 255, 255, 0.1);
                    border-radius: 0px 8px 0px 0px;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    margin-left: 12px;
                    .__back {
                        width: 8px;
                        height: 12px;
                    }
                }
                .__time {
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    color: rgba(255, 255, 255, 1);
                    .__time_date {
                        color: rgba(255, 255, 255, 1);
                        height: 16px;
                        line-height: 16px;
                        font-size: 16px;
                        font-weight: 500;
                        margin-bottom: 5px;
                    }
                    .__time_status {
                        color: rgba(255, 255, 255, 1);
                        font-size: 12px;
                        font-weight: 500;
                        white-space: nowrap;
                    }
                }
            }
        }
        .__list {
            width: 335px;
            height: 124px;
            background: #ffffff;
            border-radius: 6px;
            box-sizing: border-box;
            padding: 10px;
            margin-top: 12px;
            display: flex;
            .__cover {
                width: 104px;
                height: 104px;
                border-radius: 4px;
                margin-right: 10px;
            }
            .__info {
                flex: 1;
                display: flex;
                flex-direction: column;
                align-items: flex-start;
                justify-content: space-between;
                .__title {
                    width: 100%;
                    height: 36px;
                    line-height: 20px;
                    color: rgba(51, 51, 51, 1);
                    overflow : hidden;
                    text-overflow: ellipsis;
                    display: -webkit-box;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;
                }
                .__card {
                    display: flex;
                    align-items: center;
                    margin-top: 10px;
                    border-radius: 2px;
                    box-sizing: border-box;
                    overflow: hidden;
                    background: linear-gradient(141deg, #575D70 0%, #1E212A 100%);
                    .__discount {
                        width: 27px;
                        height: 16px;
                        background: linear-gradient(141deg, #575D70 0%, #1E212A 100%);
                        border-radius: 2px 0px 0px 2px;
                        text-align: center;
                        line-height: 16px;
                        color: #ffffff;
                        font-size: 11px;
                        font-weight: 500;
                        white-space: nowrap;
                        box-sizing: border-box;
                        margin: 0 4px;
                    }
                    .__card_wrap {
                        height: 16px;
                        background: linear-gradient(135deg, #FEE6C6 0%, #F2C3A7 100%);
                        border-radius: 0px 2px 2px 0px;
                        display: flex;
                        justify-content: center;
                        align-items: center;
                        .__card_logo {
                            width: 33px;
                            height: 12px;
                            border-radius: 0px 2px 2px 0px;
                            margin: 0 4px 0 4px;
                        }
                    }
                }
                .__button {
                    width: 201px;
                    height: 32px;
                    background: linear-gradient(180deg, #FFEBB5 0%, #FFDC7D 100%);
                    border-radius: 16px;
                    position: relative;
                    display: flex;
                    align-items: center;
                    box-sizing: border-box;
                    padding-left: 14px;
                    margin-top: 10px;
                    .__icon {
                        color: rgba(252, 38, 38, 1);
                        font-size: 10px;
                        font-weight: bold;
                        height: 12px;
                        line-height: 12px;
                        margin-top: 4px;
                    }
                    .__price {
                        color: rgba(252, 38, 38, 1);
                        font-size: 10px;
                        font-weight: bold;
                        height: 16px;
                        line-height: 18px;
                        margin-right: 4px;
                    }
                    .__button_bg {
                        width: 86px;
                        height: 32px;
                        position: absolute;
                        top: 0;
                        right: 0;
                        z-index: 0;
                    }
                    .__price_origin {
                        color: rgba(252, 38, 38, 1);
                        font-size: 12px;
                        font-weight: bold;
                        text-decoration: line-through;
                        height: 12px;
                        line-height: 12px;
                        margin-top: 4px;
                    }
                    .__price_text {
                        width: 86px;
                        height: 32px;
                        position: absolute;
                        top: 0;
                        right: 0;
                        z-index: 10;
                        text-align: center;
                        line-height: 32px;
                        color: rgba(255, 255, 255, 1);
                        font-size: 14px;
                        font-weight: bold;
                    }
                }
            }
        }
        .__shop {
            width: 345px;
            display: flex;
            align-items: center;
            margin-top: 10px;
            justify-content: space-between;
            .__items {
                width: 111px;
                height: 200px;
                display: flex;
                flex-direction: column;
                border-radius: 4px;
                align-items: center;
                background: #ffffff;
                .__cover {
                    width: 111px;
                    height: 111px;
                    border-radius: 4px 4px 0 0;
                }
                .__title {
                    width: 103px;
                    height: 20px;
                    overflow: hidden;
                    color: rgba(51, 51, 51, 1);
                    font-size: 14px;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                    margin-top: 4px;
                    margin-bottom: 7px;
                }
                .__info {
                    width: 103px;
                    display: flex;
                    align-items: center;
                    .__icon {
                        color: rgba(252, 38, 38, 1);
                        font-size: 10px;
                        font-weight: bold;
                        height: 12px;
                        line-height: 12px;
                        margin-top: 4px;
                    }
                    .__price {
                        height: 16px;
                        line-height: 16px;
                        color: rgba(252, 38, 38, 1);
                        font-size: 16px;
                        font-weight: 500;
                    }
                    .__card {
                        display: flex;
                        align-items: center;
                        border-radius: 2px;
                        box-sizing: border-box;
                        overflow: hidden;
                        background: linear-gradient(141deg, #575D70 0%, #1E212A 100%);
                        margin-left: 2px;
                        .__discount {
                            width: 27px;
                            height: 12px;
                            background: linear-gradient(141deg, #575D70 0%, #1E212A 100%);
                            border-radius: 2px 0px 0px 2px;
                            text-align: center;
                            line-height: 12px;
                            color: #ffffff;
                            font-size: 11px;
                            font-weight: 500;
                            white-space: nowrap;
                            box-sizing: border-box;
                            margin: 0 4px;
                        }
                        .__card_wrap {
                            height: 12px;
                            background: linear-gradient(135deg, #FEE6C6 0%, #F2C3A7 100%);
                            border-radius: 0px 2px 2px 0px;
                            display: flex;
                            justify-content: center;
                            align-items: center;
                            .__card_logo {
                                width: 25px;
                                height: 10px;
                                border-radius: 0px 2px 2px 0px;
                                margin: 0 4px 0 4px;
                            }
                        }
                    }
                }
                .__button {
                    width: 95px;
                    height: 26px;
                    text-align: center;
                    line-height: 26px;
                    border-radius: 24px;
                    background: linear-gradient(141deg, rgba(253, 118, 20, 1) 0%, rgba(249, 37, 37, 1) 100%);
                    color: #ffffff;
                    font-size: 14px;
                    font-weight: bold;
                    margin-top: 8px;
                }
            }
        }
    }
}
</style>

<style lang="less">
// .falseSaleActive {}
</style>